var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    is_empty: false,
    shareList: {},
    page: 1
  },

  /**
   * 获取广场信息
   */
  getShareList: function (page = 1, callBack) {
    var that = this;
    wx.showLoading({ title: 'loading', mask: true });
    app.token_md5();           
    wx.request({
      url: app.url2 + "api/share?page=" + page,
      data: {
        openid: wx.getStorageSync('openid'),
        token: wx.getStorageSync('token_md5'),
      },
      success: function (data) {
        if (typeof callBack == 'function') {
          callBack(data);
        }
        wx.hideLoading();                        
      }
    })
  },

  /**
   * 红包点击事件
   */
  toDetail: function (e) {
    var id = e.currentTarget.dataset.id;
    var type = e.currentTarget.dataset.type;
    if(type == 1){
      wx.navigateTo({
        url: '/pages/voice_box/parcel_detail/index?id=' + id,
      })
    }else{
      wx.navigateTo({
        url: '/pages/voice_box/guess/index?id=' + id,
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.getShareList(this.data.page, function (data) {
      that.setData({
        shareList: (data.data.result ? data.data.result :''),
      });
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 1200)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    this.getShareList(this.data.page += 1, function (data) {
      for (var x in data.data.result) {
        that.data.shareList.push(data.data.result[x]);
      }
      that.setData({
        shareList: that.data.shareList
      });
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }

})